import { InitBtns } from './components/init-btns'
import styles from './index.module.scss'
import { ShowType } from './type'
import { useEffect, useState } from 'react'
import { Files } from './components/files'
const { ipcRenderer } = require('electron')

function Home(): JSX.Element {
  const [path, setPath] = useState('')
  const [showType, setShowType] = useState(ShowType.init)

  const onSelectPath = (path: string): void => {
    setPath(path)
    setShowType(ShowType.showFiles)
  }

  useEffect(() => {
    ipcRenderer.on('open:file', (_e, path) => {
      onSelectPath(path)
    })
  }, [])

  return (
    <div className={styles['home-wrap']}>
      {showType === ShowType.init && <InitBtns onSelectPath={onSelectPath} />}
      {showType === ShowType.showFiles && <Files path={path} />}
    </div>
  )
}

export default Home
